package leetcode;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/12/15 8:47
 */
public class Test13 {


    /**
     * 罗马数字转整数
     */

    @Test
    public void test() {
        System.out.println(romanToInt("LVIII"));
    }


    public int romanToInt(String s) {
        Map<Character, Integer> map = new HashMap<>();
        map.put('I', 1);
        map.put('V', 5);
        map.put('X', 10);
        map.put('L', 50);
        map.put('C', 100);
        map.put('D', 500);
        map.put('M', 1000);

        char[] chars = s.toCharArray();

        int num = 0;
        for (char aChar : chars) {
            num += map.get(aChar);
        }


        return num;
    }
}
